﻿/***************************************************************************
//* Foxit Software Inc.
//* Copyright(C) 2005-2012, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
//* and trade secrets of Foxit Software Inc.                                                      *
***************************************************************************/

/**
* 基础按钮类，用来响应对应的command消息;
*/

define(function (require, exports, module) {
    var FXREADER = require('./FXReader');
    var CCommandUI = function (pReaderApp, uiDefinition) {
        //对应的命令名称;
        this.m_UIName = uiDefinition.UIName;
        this.m_CommandName = uiDefinition.CommandName;
        this.m_CreateHtmlContentFunc = uiDefinition.CreateHtmlContentFunc;
        this.m_OnCommandStateChange = uiDefinition.OnCommandStateChange;
        this.m_InitFunc = uiDefinition.Init;
        this.m_State = 0;
        if (uiDefinition.State != null)
            this.m_State = uiDefinition.State;

        var _self = this;

        this.CreateHtml = function () {
            return _self.m_CreateHtmlContentFunc.call(this, pReaderApp);
        }

        this.Init = function () {
            if (_self.m_OnCommandStateChange != null) {
                var pCommand = pReaderApp.GetCommand(_self.m_CommandName);
                if (pCommand != null) {
                    pCommand.bind("StateChange", { handler: function (State) {
                        if (_self.m_State === State)
                            return;
                        _self.m_OnCommandStateChange.call(this, State);
                        _self.m_State = State;
                    }
                    });
                }
            }
             if (this.m_InitFunc != null) {
                 _self.m_InitFunc.call(this);
            }

        }

    };

     FXREADER.CCommandUI = CCommandUI;
     return FXREADER.CCommandUI;
});